<script type="text/javascript">

$(document).ready(function(){	
	$("#flex1").flexigrid
			(
			{
			url: '<?=APPLICATION_URL_ADMIN."blog/generategrid"?>', 
			dataType: 'json',
			colModel : [
				{display: 'S.No.', name : '', width : 50, sortable : false, align: 'center'},
				{display: '<span id="bcdel"><input type="checkbox" name="deletebcchk" id="deletebcchk" onclick="return checkall(this)" /></span>', name : '', width : 50, sortable : false, align: 'center'},
				{display: 'Blog Title', name : 'title', width : 210, sortable : true, align: 'left'},
				{display: 'Post by', name : 'first_name', width : 80, sortable : true, align: 'left'},
				{display: 'User Type', name : 'user_type', width : 100, sortable : true, align: 'left'},
				{display: 'Post date', name : 'cr_date', width : 100, sortable : true, align: 'left'},
				{display: 'Comments', name : '', width : 50, sortable : false, align: 'center'},
				{display: 'Status', name : 'status', width : 50, sortable : false, align: 'center'},
				{display: 'Edit', name : 'edit', width : 50, sortable : false, align: 'center'}
				],
			buttons : [
			{name:'Delete', bclass: 'delete', onpress: deleteitem} ,
			{name:'Add New Blog', bclass: 'add', onpress: additem}
			],
			searchitems : [
				{display: 'Blog Title', name : 'title', isdefault:true},
				],
			sortname: "title",
			sortorder: "asc",
			usepager: true,
			title: '<?=$this->pageHeading?>',
			useRp: true,
			rpOptions: ['20','30','40','10'],
			rp: 10,
			showTableToggleBtn: true,
			singleSelect : true,
			height: 265,
			width: 850,
			autowidth:false
			}
			);   
	
});
function sortAlpha(com)
{ 
	jQuery('#flex1').flexOptions({newp:1, params:[{name:'letter_pressed', value: com},{name:'qtype',value:$('select[ta=qtype]').val()}]});
	jQuery("#flex1").flexReload(); 
}
function additem()
{  window.location = "<?=APPLICATION_URL_ADMIN?>blog/addblog";
}

function deleteitem(com)
{
	var r= "";
	var s="";
	var selected=false;
	for(var i=1;document.getElementById('check'+i);i++){
		if(document.getElementById('check'+i).checked==true){	
			r += document.getElementById('check'+i).value+"|";
			selected = true;
		}
	}	
	
	r += '0';
	if(selected){
		var confirmation = confirm("Are you sure want to delete ?");
		if(confirmation!=true){
			return false;
		}	
	
		$.ajax({ url: "<?=APPLICATION_URL_ADMIN."blog/deletepost"?>",
		type: "POST",
		data: ({Id:r}),
		success: function(data){			
			jQuery("#flex1").flexReload(); 
			alert('Selected records have been deleted successfully.');
		}});
	} else {
		alert('Please choose a record to delete.');
	}
}
function changestatus(Id,Status)
{

    $.ajax({ 
				type: "POST", 
				url: "<?=APPLICATION_URL_ADMIN?>blog/changestatus", 
				data: ({Id:Id,Status:Status}),
				cache: false, 
				success: function(data){	
				
				 jQuery("#flex1").flexReload(); 
			    }
		  });
}

</script>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" class="main_heading"><?=$this->pageHeading?></td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top"><table width="100%" cellpadding="0" cellspacing="0" align="center">
<tr>
<td align="left" valign="top"><table id="flex1" style="display:none;padding:0px;margin:0px;" width="100%" align="center"></table></td>
</tr>
</table></td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</td>
</tr>
</table>